package com.ruoyi.web.controller.fs;

import java.io.*;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SortListUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.fs.domain.*;
import com.ruoyi.fs.service.*;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.web.controller.tool.ExcelExporter;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案件信息Controller
 *
 * @author hero
 * @date 2024-08-30
 */
@RestController
@RequestMapping("/fs/case")
public class FsCaseController extends BaseController {
    @Autowired
    private IFsCaseService fsCaseService;
    @Autowired
    private IFsClientService fsClientService;
    @Autowired
    private IFsLawyerService fsLawyerService;
    @Autowired
    private IFsFullViewService fsFullViewService;

    @Autowired
    private IFsCaseExamineService fsCaseExamineService;
    @Autowired
    private IFsCaseFileService fsCaseFileService;
    @Autowired
    private IFsAddressService fsAddressService;
    @Autowired
    private IFsEntrustService fsEntrustService;
    @Autowired
    private IFsBatchService fsBatchService;
    @Autowired
    private IFsCapitalService fsCapitalService;
    @Autowired
    private IFsExpressInfoService fsExpressInfoService;
    @Autowired
    private IFsCaseExpressService fsCaseExpressService;
    @Autowired
    private IFsWorkOrderPostService fsWorkOrderPostService;
    @Autowired
    private IFsWorkOrderPushService fsWorkOrderPushService;
    @Autowired
    private IFsCaseRepaymentService fsCaseRepaymentService;
    @Autowired
    private IFsCaseCourtContactService fsCaseCourtContactService;

    @Autowired
    private IFsBillService fsBillService;
    @Autowired
    private ISysDictDataService sysDictDataService;
    @Autowired
    private ISysUserService sysUserService;

    private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**
     * 查询案件信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsCase fsCase) {
        startPage();

        List<FsCase> list = fsCaseService.selectFsCaseList(fsCase);
        SortListUtil<FsExpressInfo> expressSortListUtil = new SortListUtil<FsExpressInfo>();
        Map<Long, String> zfMap = new HashMap<>();
        List<FsEntrust> entrusts = fsEntrustService.selectFsEntrustList(new FsEntrust());
        for (int i = 0; i < entrusts.size(); i++) {
            zfMap.put(entrusts.get(i).getId(), entrusts.get(i).getName());
        }
        for (int i = 0; i < list.size(); i++) {
            FsCase c = list.get(i);
//            FsClient yg = fsClientService.selectFsClientById(c.getYg());
            FsClient bg = fsClientService.selectFsClientById(c.getBg());
            if (c.getTjyId() != null) {
                SysUser u = sysUserService.selectUserById(c.getTjyId());
                c.setTjy(u.getNickName());
            }
//            c.setYgDsr(yg);
            c.setBgDsr(bg);
            if (c.getIfPost() != null && c.getIfPost() == 1) {
                List<FsExpressInfo> expressInfos = fsExpressInfoService.selectFsExpressInfoListByCaseId(c.getId());
                if (!expressInfos.isEmpty()) {
                    if (expressInfos.size() > 1) {
                        expressSortListUtil.Sort(expressInfos, "getGxsj", "desc");
                    }
                    c.setLastExpress(expressInfos.get(0));
                }
            }
            if (c.getZfid() != null) {
                c.setZfName(zfMap.get(c.getZfid()));
            }
        }
        return getDataTable(list);
    }

    /**
     * 查询案件信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/listMy")
    public TableDataInfo listMy(FsCase fsCase) {
        startPage();
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        List<SysRole> roles = user.getRoles();

        List<Long> roleIds = new ArrayList<>();
        for (int i = 0; i < roles.size(); i++) {
            roleIds.add(roles.get(i).getRoleId());
        }
        if (roleIds.contains(1) || roleIds.contains(2)) {

        } else if (roleIds.contains(100L)) {
            FsLawyer lawyer = fsLawyerService.selectFsLawyerByUserId(user.getUserId());
            fsCase.setOwnerId(lawyer.getId());
        } else if (roleIds.contains(101L)) {
            fsCase.setTjyId(user.getUserId());
        }

        List<FsCase> list = fsCaseService.selectFsCaseList(fsCase);
        SortListUtil<FsExpressInfo> expressSortListUtil = new SortListUtil<FsExpressInfo>();
        for (int i = 0; i < list.size(); i++) {
            FsCase c = list.get(i);
            FsClient yg = fsClientService.selectFsClientById(c.getYg());
            FsClient bg = fsClientService.selectFsClientById(c.getBg());
            if (c.getTjyId() != null) {
                SysUser u = sysUserService.selectUserById(c.getTjyId());
                c.setTjy(u.getNickName());
            }
            c.setYgDsr(yg);
            c.setBgDsr(bg);
            if (c.getIfPost() != null && c.getIfPost() == 1) {
                List<FsExpressInfo> expressInfos = fsExpressInfoService.selectFsExpressInfoListByCaseId(c.getId());
                if (!expressInfos.isEmpty()) {
                    if (expressInfos.size() > 1) {
                        expressSortListUtil.Sort(expressInfos, "getGxsj", "desc");
                    }
                    c.setLastExpress(expressInfos.get(0));
                }
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出案件信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:export')")
    @Log(title = "案件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FsCase fsCase) {
        List<FsCase> list = fsCaseService.selectFsCaseList(fsCase);
        ExcelUtil<FsCase> util = new ExcelUtil<FsCase>(FsCase.class);
        util.exportExcel(response, list, "案件信息数据");
    }

    /**
     * 获取案件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('fs:case:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        FsCase c = fsCaseService.selectFsCaseById(id);
        FsClient yg = fsClientService.selectFsClientById(c.getYg());
        FsClient bg = fsClientService.selectFsClientById(c.getBg());
        FsFullView fullView = fsFullViewService.selectFsFullViewByBh(c.getBh());
        if (fullView != null) {
            c.setFullView(fullView);
        }
        c.setYgDsr(yg);
        c.setBgDsr(bg);
        return success(c);
    }

    /**
     * 新增案件信息
     */
    @PreAuthorize("@ss.hasPermi('fs:case:add')")
    @Log(title = "案件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsCase fsCase) {
        return toAjax(fsCaseService.insertFsCase(fsCase));
    }

    /**
     * 修改案件信息
     */
    @PreAuthorize("@ss.hasPermi('fs:case:edit')")
    @Log(title = "案件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsCase fsCase) {
        return toAjax(fsCaseService.updateFsCase(fsCase));
    }

    /**
     * 删除案件信息
     */
    @PreAuthorize("@ss.hasPermi('fs:case:remove')")
    @Log(title = "案件信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fsCaseService.deleteFsCaseByIds(ids));
    }


    /**
     * 查询案件信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/listExamine/{id}")
    public AjaxResult listExamine(@PathVariable("id") Long id) {
        FsCaseExamine query = new FsCaseExamine();
        query.setCaseId(id);
        List<FsCaseExamine> list = fsCaseExamineService.selectFsCaseExamineList(query);
        return success(list);
    }


    /**
     * 结案
     */
    @PreAuthorize("@ss.hasPermi('fs:case:edit')")
    @Log(title = "结案", businessType = BusinessType.INSERT)
    @PostMapping("/ja")
    public AjaxResult ja(@RequestBody String json) {
        JSONObject obj = JSONObject.parseObject(json);
        Long id = obj.getLong("id");
        Integer sdzt = obj.getInteger("sdzt");
        Integer ifBill = obj.getInteger("ifBill");
        String ah = obj.getString("ah");
        String remark = obj.getString("remark");
        FsCase c = fsCaseService.selectFsCaseById(id);
        if (StringUtils.isNotBlank(ah)) {
            c.setAh(ah);
        }
        c.setAjzt(2);
        c.setSdbs(1);
        c.setSdzt(sdzt);
        c.setRemark(remark);
        c.setGxsj(df.format(new Date()));
        fsCaseService.updateFsCase(c);
        FsFullView fullView = fsFullViewService.selectFsFullViewByBh(c.getBh());
        if (fullView == null) {
            fullView = new FsFullView();
            fullView.setBh(c.getBh());
            fullView.setAh(c.getAh());
            fullView.setAjmc(c.getAjmc());
            fullView.setLaay(c.getSqlaayMc());
            fullView.setJbfy(c.getFymc());
            fullView.setZdslfy(c.getFymc());
            fullView.setDlrid(c.getOwnerId());
            fullView.setDlr(c.getOwner());
            fullView.setJarq(df.format(new Date()));
            fullView.setJaay(c.getSqlaayMc());
            fullView.setJafs(sysDictDataService.selectDictLabel("fs_ja_type", sdzt.toString()));
            fullView.setRemark("手动结案");
            fsFullViewService.insertFsFullView(fullView);
        }

        if (ifBill == 1) {
            FsBill bill = new FsBill();
            FsClient yg = fsClientService.selectFsClientById(c.getYg());
            FsClient bg = fsClientService.selectFsClientById(c.getBg());
            bill.setCaseId(c.getId());
            bill.setAh(c.getAh());
            bill.setBh(c.getBh());
            bill.setOwnerId(c.getOwnerId());
            bill.setOwner(c.getOwner());
            bill.setAjmc(c.getAjmc());
            bill.setYgmc(yg.getXm());
            bill.setBgmc(bg.getXm());
            if (c.getSqbdje() != null) {
                BigDecimal yhze = c.getSqbdje().multiply(new BigDecimal(1000));
                bill.setYhze(yhze);
            }
            bill.setSfkq("N");
            bill.setSfjq("N");
            fsBillService.insertFsBill(bill);
        }
        return success();
    }


    /**
     * 生成还款账单
     */
    @PreAuthorize("@ss.hasPermi('fs:case:edit')")
    @Log(title = "生成还款账单", businessType = BusinessType.INSERT)
    @GetMapping("/initBill/{id}")
    public AjaxResult initBill(@PathVariable("id") Long id) {
        FsCase c = fsCaseService.selectFsCaseById(id);
        FsBill bill = fsBillService.selectFsBillByCaseId(id);
        if (bill != null) {
            return success(bill);
        } else {
            bill = new FsBill();
        }
        FsClient yg = fsClientService.selectFsClientById(c.getYg());
        FsClient bg = fsClientService.selectFsClientById(c.getBg());
        bill.setCaseId(c.getId());
        bill.setAh(c.getAh());
        bill.setBh(c.getBh());
        bill.setOwnerId(c.getOwnerId());
        bill.setOwner(c.getOwner());
        bill.setAjmc(c.getAjmc());
        bill.setYgmc(yg.getXm());
        bill.setBgmc(bg.getXm());
        if (c.getSqbdje() != null) {
            BigDecimal yhze = c.getSqbdje().multiply(new BigDecimal(1000));
            bill.setYhze(yhze);
        }
        bill.setSfkq("N");
        bill.setSfjq("N");
        fsBillService.insertFsBill(bill);
        return success(bill);
    }

    /**
     * 导出案件信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:export')")
    @Log(title = "案件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/download")
    public void download(HttpServletResponse response, FsCase fsCase) {
        response.setHeader("Content-Disposition", "attachment;fileName=总览");
        response.setCharacterEncoding("utf-8");
        response.setContentType("multipart/form-data");
        File file = new File("/opt/zl.xlsx");
        try (InputStream inputStream = new FileInputStream(file)) {
            OutputStream os = response.getOutputStream();
            byte[] b = new byte[1024];
            int length;
            while ((length = inputStream.read(b)) > 0) {
                os.write(b, 0, length);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 查询资方信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/listTjy")
    public AjaxResult listTjy() {
        SysUser user = new SysUser();
        user.setRoleId(101L);
        List<SysUser> list = sysUserService.selectUserListByRoleId(user);
//        List<SysUser> result = new ArrayList<>();
//
//        for (int i = 0; i < list.size(); i++) {
//            SysUser u = list.get(i);
//            if (Arrays.asList(u.getRoleIds()).contains(101L)) {
//                result.add(u);
//            }
//        }
        return success(list);
    }

    /**
     * 查询案件信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/listFile/{id}")
    public AjaxResult listFile(@PathVariable("id") Long id) {
        FsCaseFile query = new FsCaseFile();
        query.setCaseId(id);
        List<FsCaseFile> list = fsCaseFileService.selectFsCaseFileList(query);
        List<FsCaseFile> result = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            FsCaseFile caseFile = list.get(i);
            if (caseFile.getOosUrl() != null) {
                result.add(caseFile);
            }
        }
        return success(result);
    }

    /**
     * 查询省份
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/listSf")
    public AjaxResult listSf() {
        FsAddress query = new FsAddress();
        query.setPcode("000000");
        List<FsAddress> list = fsAddressService.selectFsAddressList(query);
        return success(list);
    }

    /**
     * 查询市
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/listChild/{id}")
    public AjaxResult listChild(@PathVariable("id") Long id) {
        FsAddress address = fsAddressService.selectFsAddressById(id);
        FsAddress query = new FsAddress();
        query.setPcode(address.getCode());
        List<FsAddress> list = fsAddressService.selectFsAddressList(query);
        return success(list);
    }

    /**
     * 查询资方信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/listZf")
    public AjaxResult listZf() {
        FsEntrust entrust = new FsEntrust();
        List<FsEntrust> list = fsEntrustService.selectFsEntrustList(entrust);
        return success(list);
    }

    /**
     * 查询资方信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/listBatch/{id}")
    public AjaxResult listBatch(@PathVariable("id") Long id) {
        FsBatch batch = new FsBatch();
        batch.setZfid(id);
        List<FsBatch> list = fsBatchService.selectFsBatchList(batch);
        return success(list);
    }

    /**
     * 查询诉讼主体
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/listSszt")
    public AjaxResult listSszt() {
        FsCapital capital = new FsCapital();
        List<FsCapital> list = fsCapitalService.selectFsCapitalList(capital);
        return success(list);
    }


    /**
     * 导出案件信息列表
     */
    @PreAuthorize("@ss.hasPermi('fs:case:export')")
    @Log(title = "案件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportNwd")
    public void exportNwd(HttpServletResponse response, FsCase fsCase) {
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        List<SysRole> roles = user.getRoles();

        List<Long> roleIds = new ArrayList<>();
        for (int i = 0; i < roles.size(); i++) {
            roleIds.add(roles.get(i).getRoleId());
        }
        if (roleIds.contains(1) || roleIds.contains(2)) {

        } else if (roleIds.contains(100L)) {
            FsLawyer lawyer = fsLawyerService.selectFsLawyerByUserId(user.getUserId());
            fsCase.setOwnerId(lawyer.getId());
        } else if (roleIds.contains(101L)) {
            fsCase.setTjyId(user.getUserId());
        }
        List<FsEntrust> entrusts = fsEntrustService.selectFsEntrustList(new FsEntrust());
        Map<Long, String> zfNameMap = new HashMap<>();
        for (int i = 0; i < entrusts.size(); i++) {
            zfNameMap.put(entrusts.get(i).getId(), entrusts.get(i).getName());
        }
        List<FsCase> list = new ArrayList<>();
        if (fsCase.getZfid() == null) {
            for (int i = 0; i < entrusts.size(); i++) {
                fsCase.setZfid(entrusts.get(i).getId());
                list.addAll(fsCaseService.selectFsCaseList(fsCase));
            }
        } else {
            list.addAll(fsCaseService.selectFsCaseList(fsCase));
        }
        for (int i = 0; i < list.size(); i++) {
            FsCase caseVo = list.get(i);
            caseVo.setZfName(zfNameMap.get(caseVo.getZfid()));
            FsClient bg = fsClientService.selectFsClientById(caseVo.getBg());
            caseVo.setBgDsr(bg);
            int zt = caseVo.getZt();
            if (zt == 3 || zt == 5 || zt == 31) {
                FsCaseExamine query = new FsCaseExamine();
                query.setCaseId(caseVo.getId());
                List<FsCaseExamine> examineList = fsCaseExamineService.selectFsCaseExamineList(query);
                caseVo.setExamineList(examineList);
            }
        }
        SysUser query = new SysUser();
        query.setRoleId(101L);
        List<SysUser> users = sysUserService.selectUserListByRoleId(query);
        List<FsAddress> addresses = fsAddressService.selectFsAddressList(new FsAddress());
        try {
            InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template/案件跟进信息模版.xlsx");
            ExcelExporter.exportDataToTemplate(response, list, inputStream, users, addresses);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 根据case ID查询最后的邮寄工单
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/getPostByCaseId/{id}")
    public AjaxResult getPostByCaseId(@PathVariable("id") Long id) {
        FsWorkOrderPost post = new FsWorkOrderPost();
        post.setCaseId(id);
        List<FsWorkOrderPost> list = fsWorkOrderPostService.selectFsWorkOrderPostList(post);
        SortListUtil<FsWorkOrderPost> sortListUtil = new SortListUtil<FsWorkOrderPost>();
        if (!list.isEmpty()) {
            if (list.size() > 1) {
                sortListUtil.Sort(list, "getCreateTime", "desc");
            }
            return success(list.get(0));
        }
        return success();
    }

    /**
     * 新增邮寄工单
     */
    @PreAuthorize("@ss.hasPermi('fs:case:add')")
    @Log(title = "邮寄工单", businessType = BusinessType.INSERT)
    @PostMapping("/post")
    public AjaxResult addPost(@RequestBody FsWorkOrderPost fsWorkOrderPost) {
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        if (user != null) {
            fsWorkOrderPost.setCjr(user.getUserId());
            fsWorkOrderPost.setCreateBy(user.getNickName());
        }
        FsCase fsCase = fsCaseService.selectFsCaseById(fsWorkOrderPost.getCaseId());
        if (fsCase != null) {
            fsWorkOrderPost.setAjmc(fsCase.getAjmc());
            fsWorkOrderPost.setNbajbh(fsCase.getNbajbh());
        }
        fsWorkOrderPost.setId(null);
        fsWorkOrderPost.setZt(1);
        return toAjax(fsWorkOrderPostService.insertFsWorkOrderPost(fsWorkOrderPost));
    }

    /**
     * 修改邮寄工单
     */
    @PreAuthorize("@ss.hasPermi('fs:case:edit')")
    @Log(title = "邮寄工单", businessType = BusinessType.UPDATE)
    @PutMapping("/post")
    public AjaxResult editPost(@RequestBody FsWorkOrderPost fsWorkOrderPost) {
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        if (user != null) {
            fsWorkOrderPost.setUpdateBy(user.getNickName());
        }
        return toAjax(fsWorkOrderPostService.updateFsWorkOrderPost(fsWorkOrderPost));
    }


    /**
     * 根据case ID查询最后的邮寄工单
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/getPushByCaseId/{id}")
    public AjaxResult getPushByCaseId(@PathVariable("id") Long id) {
        FsWorkOrderPush push = new FsWorkOrderPush();
        push.setCaseId(id);
        List<FsWorkOrderPush> list = fsWorkOrderPushService.selectFsWorkOrderPushList(push);
        SortListUtil<FsWorkOrderPush> sortListUtil = new SortListUtil<>();
        if (!list.isEmpty()) {
            if (list.size() > 1) {
                sortListUtil.Sort(list, "getCreateTime", "desc");
            }
            return success(list.get(0));
        }
        return success();
    }

    /**
     * 新增案件重提工单
     */
    @PreAuthorize("@ss.hasPermi('fs:case:add')")
    @Log(title = "案件重提工单", businessType = BusinessType.INSERT)
    @PostMapping("/push")
    public AjaxResult addPush(@RequestBody FsWorkOrderPush fsWorkOrderPush) {
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        if (user != null) {
            fsWorkOrderPush.setCjr(user.getUserId());
            fsWorkOrderPush.setCreateBy(user.getNickName());
        }
        FsCase fsCase = fsCaseService.selectFsCaseById(fsWorkOrderPush.getCaseId());
        if (fsCase != null) {
            fsWorkOrderPush.setAjmc(fsCase.getAjmc());
            fsWorkOrderPush.setNbajbh(fsCase.getNbajbh());
        }
        fsWorkOrderPush.setId(null);
        fsWorkOrderPush.setZt(1);
        return toAjax(fsWorkOrderPushService.insertFsWorkOrderPush(fsWorkOrderPush));
    }

    /**
     * 修改邮寄工单
     */
    @PreAuthorize("@ss.hasPermi('fs:case:edit')")
    @Log(title = "案件重提工单", businessType = BusinessType.UPDATE)
    @PutMapping("/push")
    public AjaxResult editPush(@RequestBody FsWorkOrderPush fsWorkOrderPush) {
        LoginUser loginUser = getLoginUser();
        SysUser user = loginUser.getUser();
        if (user != null) {
            fsWorkOrderPush.setUpdateBy(user.getNickName());
        }
        return toAjax(fsWorkOrderPushService.updateFsWorkOrderPush(fsWorkOrderPush));
    }


    /**
     * 根据case ID查询还款计划
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/getRepaymentByCaseId/{id}")
    public AjaxResult getRepaymentByCaseId(@PathVariable("id") Long id) {
        FsCaseRepayment repayment = fsCaseRepaymentService.getCaseRepaymentDetailByCaseId(id);
        return success(repayment);
    }

    /**
     * 根据case ID查询法院联系信息
     */
    @PreAuthorize("@ss.hasPermi('fs:case:list')")
    @GetMapping("/getCourtContact/{id}")
    public AjaxResult getCourtContact(@PathVariable("id") Long id) {
        FsCaseCourtContact contact = new FsCaseCourtContact();
        contact.setCaseId(id);
        List<FsCaseCourtContact> contacts = fsCaseCourtContactService.selectFsCaseCourtContactList(contact);
        return success(contacts);
    }
}
